import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

/// 服务
class HttpServicesService {
  /// 服务清单
  static Future<Response> serviceList([int noLink]) {
    return BaseConfig.httpBase.get('/api/services', {
      'no_link': noLink,
    });
  }

  /// 批量禁用服务清单
  static Future<Response> serviceBatchDeactivate(List<int> ids) {
    return BaseConfig.httpBase.postJson('/api/services/batch_deactivate', {
      'service_ids': ids,
    });
  }

  /// 批量激活服务清单
  static Future<Response> serviceBatchActivate(List<int> ids) {
    return BaseConfig.httpBase.postJson('/api/services/batch_activate', {
      'service_ids': ids,
    });
  }

  /// 批量删除服务清单
  static Future<Response> serviceBatchDelete(List<int> ids) {
    return BaseConfig.httpBase.postJson('/api/services/batch_delete', {
      'service_ids': ids,
    });
  }

  /// 创建服务
  static Future<Response> createService({
    int category_id,
    String name,
    String code,
    String description,
    int enable_sell,
    String currency_code,
    double price,
    int tax_id,
    int is_tax_inclusive,
    int enable_purchase,
    String purchase_currency_code,
    double purchase_price,
    int purchase_tax_id,
    int purchase_is_tax_inclusive,
    List<String> categories,
    List<int> attachment_ids,
  }) {
    return BaseConfig.httpBase.postJson('/api/services', {
      "category_id": category_id,
      "name": name,
      "code": code,
      'currency_code': currency_code,
      "description": description,
      "enable_sell": enable_sell,
      "price": price,
      "tax_id": tax_id,
      "is_tax_inclusive": is_tax_inclusive,
      "enable_purchase": enable_purchase,
      if (purchase_currency_code != null) ...{
        "purchase_currency_code": purchase_currency_code,
      },
      "purchase_price": purchase_price,
      "purchase_tax_id": purchase_tax_id,
      "purchase_is_tax_inclusive": purchase_is_tax_inclusive,
      "categories": categories,
      "attachment_ids": attachment_ids,
    });
  }

  /// 显示服务
  static Future<Response> showService(int serviceId) {
    return BaseConfig.httpBase.get('/api/services/$serviceId', {});
  }

  /// 删除服务
  static Future<Response> deleteService(int serviceId) {
    return BaseConfig.httpBase.deleteJson('/api/services/$serviceId', {});
  }

  /// 禁用服务
  static Future<Response> deactivateService(int serviceId) {
    return BaseConfig.httpBase
        .postJson('/api/services/$serviceId/deactivate', {});
  }

  /// 激活服务
  static Future<Response> activateService(int serviceId) {
    return BaseConfig.httpBase
        .postJson('/api/services/$serviceId/activate', {});
  }

  /// 更新服务
  static Future<Response> updateService(
    int serviceId, {
    int category_id,
    String name,
    String code,
    String description,
    int enable_sell,
    String currency_code,
    double price,
    int tax_id,
    int is_tax_inclusive,
    int enable_purchase,
    String purchase_currency_code,
    double purchase_price,
    int purchase_tax_id,
    int purchase_is_tax_inclusive,
    List<String> categories,
    List<int> attachment_ids,
  }) {
    return BaseConfig.httpBase.putJson('/api/services/$serviceId', {
      "category_id": category_id,
      "name": name,
      "code": code,
      "description": description,
      "enable_sell": enable_sell,
      "currency_code": currency_code,
      "price": price,
      "tax_id": tax_id,
      "is_tax_inclusive": is_tax_inclusive,
      "enable_purchase": enable_purchase,
      "purchase_currency_code": purchase_currency_code,
      "purchase_price": purchase_price,
      "purchase_tax_id": purchase_tax_id,
      "purchase_is_tax_inclusive": purchase_is_tax_inclusive,
      "categories": categories,
      "attachment_ids": attachment_ids
    });
  }
}
